package com.haoshuang.zhouzhoubang.ui.dialog

import android.content.Context
import com.haoshuang.zhouzhoubang.R
import com.haoshuang.zhouzhoubang.databinding.DialogShowChooseOrderScreenBinding
import com.haoshuang.zhouzhoubang.model.bean.OrderScreenStatusBean
import com.haoshuang.zhouzhoubang.ui.adapter.OrderScreenStatusAdapter
import com.lxj.xpopup.impl.PartShadowPopupView
import com.mufeng.libs.core.setOnItemClick
import com.mufeng.libs.utils.view.clickWithTrigger
import com.mufeng.libs.utils.view.vertical

/**
 * 首页订单筛选弹窗
 * @constructor
 */
class ChooseOrderStatusScreenDialog(
    context: Context,
    private val status: Int,
    private val onChooseOrderStatus: (status: Int?) -> Unit,
    private val onSearch: () -> Unit,
) : PartShadowPopupView(context) {

    private lateinit var binding: DialogShowChooseOrderScreenBinding

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_show_choose_order_screen
    }

    private val orderStatusList = arrayListOf(
        OrderScreenStatusBean(statusName = "待抢单", status = 0, isChecked = false),
        OrderScreenStatusBean(statusName = "待预约", status = 9, isChecked = false),
        OrderScreenStatusBean(statusName = "待确认", status = 8, isChecked = false),
        OrderScreenStatusBean(statusName = "待上门", status = 1, isChecked = false),
        OrderScreenStatusBean(statusName = "已超时", status = 7, isChecked = false),
        OrderScreenStatusBean(statusName = "服务中", status = 2, isChecked = false),
        OrderScreenStatusBean(statusName = "待验收", status = 6, isChecked = false),
        OrderScreenStatusBean(statusName = "已完成", status = 3, isChecked = false),
        OrderScreenStatusBean(statusName = "返工单", status = 5, isChecked = false),
        OrderScreenStatusBean(statusName = "退款/售后", status = 4, isChecked = false),
    )

    private val adapter = OrderScreenStatusAdapter(orderStatusList)

    override fun onCreate() {
        super.onCreate()
        binding = DialogShowChooseOrderScreenBinding.bind(popupImplView)

        binding.llSearch.clickWithTrigger{
            dismiss()
            onSearch()
        }



        binding.recyclerView.vertical(5)
            .adapter = adapter

        orderStatusList.forEach {
            it.isChecked = it.status == status
        }
        adapter.notifyDataSetChanged()

        adapter.setOnItemClick { view, position,_ ->
            val item = adapter.getItem(position)
            dismiss()
            onChooseOrderStatus(item?.status)
        }

    }

}